package edu.pku.sei.transformation.editor.model;

import org.w3c.dom.Element;

import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.transformation.editor.model.namespace.NamedElement;

public class TransformationFormalParameter extends NamedElement {
	private MetaModel metamodel;
	
	public MetaModel getMetamodel() {
		return metamodel;
	}
	public void setMetamodel(MetaModel metamodel) {
		if (this.metamodel != metamodel) {
			MetaModel oldValue = this.metamodel;
			this.metamodel = metamodel;
			firePropertyChange(ModelPackage.TFP_METAMODEL, oldValue, this.metamodel);			
		}
	}
	
	@Override
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeNodeNotContain(root, ModelPackage.TFP_METAMODEL, metamodel);
	}
	
	@Override
	public void deSerialize(Element root) {
		super.deSerialize(root);
		this.metamodel = (MetaModel) XMLUtility.xmlInstance.deSerializeNodeNotContain(root, ModelPackage.TFP_METAMODEL, this);
	}
	
	@Override
	public void dynamicSet(String featureID, Object value) {
		if (ModelPackage.TFP_METAMODEL.equals(featureID)) {
			this.metamodel = (MetaModel) value;
		} else {
			super.dynamicSet(featureID, value);
		}
	}
	
	@Override
	public String toString() {
		if (metamodel == null)
			return getName()+" : null";
		else
			return getName()+":"+metamodel.getName();
	}
	
	public Transformation getTransformation() {
		return (Transformation) this.container;
	}
	
	public void setTransformation(Transformation trans) {
		this.container = trans;
	}
}
